﻿using Ninject;
using Ninject.Modules;
using NinjectSamples.example;

namespace NinjectSamples
{
	public class ClassicUsageWithModules
	{
		private IKernel _kernel;

		public ClassicUsageWithModules()
		{
			_kernel = new StandardKernel(new EmailSenderModule());
		}

		public void SendSomeReallyImportantEmail(string emailTo, string message)
		{
			//Note: resolving a dependency from the kernel is a bad idea, this is for dmostration purposes only
			var emailSender = _kernel.Get<IEmailSender>();

			emailSender.Send(emailTo, message);
		}
	}

	public class EmailSenderModule : NinjectModule
	{
		public override void Load()
		{
			Bind<IEmailSender>().To<SmtpEmailSender>();
			Bind<IEmailSenderConfiguration>().To<SmtpEmailConfiguration>();
		}
	}
}
